package com.zztl.infiniteBand.presenter

import android.content.Context

import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.ServiceNoticeBean
import com.zztl.infiniteBand.model.SysOrCompanyBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.MsgTypeRequest
import com.zztl.infiniteBand.ui.view.mvpview.MessageListView


/**
 * @desc
 * @auth ${user}
 * @time 2018/6/14  10:40
 */
class MessageListPresenter : BasePresenter<MessageListView>() {
    fun getMsgListByType(request: MsgTypeRequest, context: Context) {
        if ("serviceNotice" == request.messageTypeId) {
            addSubscribe(RetorfitServiceManger
                    .observe(RetorfitServiceManger.instance!!.apiService
                    .getServiceMessageList(DataConverter.instance.toJson(request)))
                    .subscribe(object : FilterSubscriber<ServiceNoticeBean>(context) {
                        override fun success(serviceNoticeBean: ServiceNoticeBean) {
                            view!!.failOrSuccess()
                            view!!.getListSuccess(serviceNoticeBean)
                        }

                        override fun fail() {
                            super.fail()
                            view!!.failOrSuccess()
                            view!!.getListFail()
                        }
                    }))
        } else {
            addSubscribe(RetorfitServiceManger
                    .observe(RetorfitServiceManger.instance!!.apiService
                    .getCompanyOrSysMessageList(DataConverter.instance.toJson(request)))
                    .subscribe(object : FilterSubscriber<SysOrCompanyBean>(context) {
                        override fun success(sysOrCompanyBean: SysOrCompanyBean) {
                            view!!.failOrSuccess()
                            view!!.getListSuccess(sysOrCompanyBean)
                        }

                        override fun fail() {
                            super.fail()
                            view!!.failOrSuccess()
                            view!!.getListFail()
                        }
                    }))
        }
    }
}
